package com.xm.controller;

import com.xm.pojo.R;
import com.xm.pojo.foot;
import com.xm.service.footService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/Foots")
@CrossOrigin
public class footController {


    @Autowired
    private footService footService;


    /*展示1用户足迹*/
    @GetMapping("/footAll/{userId}")
    public R footAll(@PathVariable int userId){
        List<foot> list=footService.footAll(userId);
        if(list.size()>0){
            return R.OK().errorMsg("足迹展示成功!").data("list",list);
        }else{
            return R.ERROR().errorMsg("暂无足迹!");
        }
    }

    /*删除足迹(单个)*/
    @DeleteMapping("/deleteFoot/{id}")
    public R delContact(@PathVariable int id){
        boolean flag=footService.delFoot(id);
        if(flag){
            return R.OK().errorMsg("已删除足迹！");
        }else{
            return R.ERROR().errorMsg("足迹删除失败!");
        }
    }

    /*删除足迹(多个)*/
    @DeleteMapping("/deleteFoot")
    public R delContact(@RequestBody int[] ids){
        boolean falgs=true;
        for(int i=0;i<ids.length;i++){
            boolean flag=footService.delFoot(ids[i]);
            if(!flag){
                falgs=false;
                continue;
            }
        }
        if(falgs){
            return R.OK().errorMsg("已删除足迹！");
        }else{
            return R.ERROR().errorMsg("足迹删除失败!");
        }
    }
    /*删除足迹(全部)*/
    @DeleteMapping("/deleteFootAll/{userId}")
    public R delContactAll(@PathVariable int userId){
        boolean flag=footService.delFootAll(userId);
        if(flag){
            return R.OK().errorMsg("已删除足迹！");
        }else{
            return R.ERROR().errorMsg("足迹删除失败!");
        }
    }

}
